package frame;

import dao.UserDaoImpl;
import entity.User;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class UserMainFrame extends JFrame{
	
	private static final long serialVersionUID = 1L; 
	User user;
	
	public UserMainFrame() {}
	public UserMainFrame(User u) {
		
		Map<String, User> users  = UserDaoImpl.getUsers();
		
		Iterator<Entry<String, User>> iter = users.entrySet().iterator();
		while(iter.hasNext()) {
			Map.Entry<String, User> entry=iter.next();
			if(u.getId().equals(entry.getKey())) {
				user = entry.getValue();
				break;
			}		
		}
		
        this.setTitle("????????????????????????" + user.getName() + "???????");	        
        this.setBounds(100, 100, 500, 375);
	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        init(user);
        this.setVisible(true);
   
    }
	
    private void init(User u) {
		// TODO Auto-generated method stub
    	JMenuBar menuBar = new JMenuBar();// ?????????????
        setJMenuBar(menuBar);// ??????????????????????????
        
        JMenu menu = new JMenu("???????");// ???????????
        menuBar.add(menu);// ????????????????????????
        
        JMenu sonMenu = new JMenu("?????????");// ?????????????????
        menu.add(sonMenu);// ??????????????????????????
        
        JMenuItem sonMenuItem1 = new JMenuItem("??????????");// ?????????????????
        sonMenuItem1.addActionListener(new ItemListener());// ??????????????????
        
        sonMenu.add(sonMenuItem1);// ?????????????????????????????
        
        JMenuItem sonMenuItem2 = new JMenuItem("???????????");// ?????????????????
        sonMenuItem2.addActionListener(new ItemListener());// ??????????????????
        sonMenu.add(sonMenuItem2);// ?????????????????????????????
        
        JMenuItem menuItem1 = new JMenuItem("??????");// ????????????
        menuItem1.addActionListener((ActionListener) new ItemListener());// ??????????????????
        menu.add(menuItem1);// ???????????????????????
        
        JMenuItem menuItem2 = new JMenuItem("??????");// ????????????
        menuItem2.addActionListener((ActionListener) new ItemListener());// ??????????????????
        menu.add(menuItem2);// ???????????????????????
        
        JMenu menu2 = new JMenu("????????");// ???????????
        menuBar.add(menu2);// ????????????????????????
        
        JMenuItem menuItem3 = new JMenuItem("????????");// ????????????
        menuItem3.addActionListener(new ItemListener());// ??????????????????
        menu2.add(menuItem3);// ???????????????????????
        
        JMenu menu3 = new JMenu("???????????");// ???????????
        menuBar.add(menu3);// ????????????????????????
        
        JMenuItem menuItem4 = new JMenuItem("???????????");// ????????????
        menuItem3.addActionListener(new ItemListener());// ??????????????????
        menu3.add(menuItem4);// ???????????????????????
        
        
	}

	private class ItemListener implements ActionListener {
 
		public void actionPerformed1(ActionEvent e) {
            JMenuItem menuItem = (JMenuItem) e.getSource();
            System.out.println("??????????????" + menuItem.getText());
        }

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			
		}
    }
    public static void main(String[]args){
    	new UserMainFrame();
 	  
    }

}
